/*
 * DataValidation.cpp
 *
 *  Created on: 26/08/2011
 *      Author: jairo
 */

#include "bilbao/validation/DataValidation.h"

namespace bilbao
{
	namespace validation
	{
		//--------------------------------------------------------------------------------
		// Construtor e destrutor
		//--------------------------------------------------------------------------------
		DataValidation::DataValidation( void )
		{
			// Do nothing
		}
		//--------------------------------------------------------------------------------
		DataValidation::~DataValidation( void )
		{
			// Do nothing
		}
		//--------------------------------------------------------------------------------
		int DataValidation::validateSaleData( XML data )
		{
			int len = data.size();
			String str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + data.substr( 0, 4 )
					+ " xmlns=\"http://www.portalfiscal.inf.br/cfe\"\n"
					+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
					+ "xsi:schemaLocation=\"http://www.portalfiscal.inf.br/cfe home/software/xsd/dadosVenda_v0.01.xsd\""
					+ data.substr( 4, len - 4 );

			std::cout << str << std::endl;
			std::istringstream ss( str );
			try
			{
				std::auto_ptr< TCFe > c( CFe( ss ) );
			}
			catch ( const xml_schema::exception& e )
			{
				std::cerr << e << std::endl;
				return -1;
			}
			return 0;
		}
		//--------------------------------------------------------------------------------

	} // namespace validation
} // namespace bilbao
